using System;
using System.Data;
using System.Data.SqlClient;

using PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;

namespace PHSRAG.Insight21.ClinicalTrials
{
   /// <summary>
   /// The BudgetMilestoneVisit is the facade over a single Budget Milestone Visit.
   /// It holds details specific to an individual visit and task or procedure combination
   /// </summary>
   public class BudgetMilestoneVisit : BusinessObject
   {

      #region Constants
      private const string BudgetMilestoneVisitKey = "BudgetMilestoneVisit_F52323F3-AE23-4135-BE10-4006E4B47755";
      private const string TableName = "BudgetMilestoneVisit";
      #endregion

      #region Instance Variables
      private DataRow dataRow;
      #endregion

      #region Public Properties
      /// <summary>
      /// Unique Id for this BudgetMilestoneVisit
      /// </summary>
      public int Id
      {
         get
         {
            return (int)dataRow["Id"]; 
         }
      }

      /// <summary>
      /// Id of the related Budget Visit
      /// </summary>
      public int BudgetVisitId
      {
         get
         {
            return (int)dataRow["ClinicalTrialBudgetVisitId"];
         }
         set
         {
            dataRow["ClinicalTrialBudgetVisitId"] = value;
         }
      }

      /// <summary>
      /// Name of the related class (BudgetTask or BudgetProcedure)
      /// </summary>
      public string RelateClass
      {
         get
         {
            return dataRow["RelateClass"].ToString( );
         }
         set
         {
            dataRow["RelateClass"] = value;
         }
      }

      /// <summary>
      /// Id of the related task or procedure
      /// </summary>
      public int RelateId
      {
         get
         {
            return (int)dataRow["RelateId"];
         }
         set
         {
            dataRow["RelateId"] = value;
         }
      }

      /// <summary>
      /// Boolean indicating whether this task or procedure is required for this visit
      /// </summary>
      public bool Required
      {
         get
         {
            object o = dataRow["Required"];
            return (o == DBNull.Value) ? false : (bool)o;
         }
         set
         {
            dataRow["Required"] = value;
         }
      }

      /// <summary>
      /// Boolean indicating whether this task or procedure is part of the standard of care for this visit
      /// </summary>
      public bool StandardOfCare
      {
         get
         {
            object o = dataRow["StandardOfCare"];
            return (o == DBNull.Value) ? false : (bool)o;
         }
         set
         {
            dataRow["StandardOfCare"] = value;
         }
      }
      #endregion

      #region Constructor
      /// <summary>
      /// Initialize the base class with the specified cache policy and sets the dataRow member.
      /// </summary>
      public BudgetMilestoneVisit( ICachePolicy cachePolicy, DataRow row ) : base ( cachePolicy )
      {
         dataRow = row;
      }
      #endregion

      #region Base Methods
      /// <summary>
      /// Cache this instance using the prevalent cache policy.
      /// </summary>
      public override void Cache( )
      {
         CachePolicy.Cache( BudgetMilestoneVisitKey, this );
      }

      /// <summary>
      /// Remove this instance from the cache using the prevalent cache policy.
      /// </summary>
      public override void UnCache( )
      {
         CachePolicy.UnCache( BudgetMilestoneVisitKey );
      }

      /// <summary>
      /// Load method is not used
      /// </summary>
      /// <param name="connectionString"></param>
      /// <param name="args"></param>
      public override void Load( string connectionString, params object[] args )
      {
         throw new Exception("BudgetMilestoneVisit is not directly loadable");
      }
      #endregion

   }// END CLASS DEFINITION BudgetMilestoneVisit
}